﻿using B.S.Base.Read.API.Application.Command;
using MediatR;
using Microsoft.EntityFrameworkCore;
using WEBAPI.API.Application.Command;
using WEBAPI.API.Dto;
using WEBAPI.Damoin;
using WEBAPI.ErroeCode;
using WEBAPI.Indaseture.Infasetures;

namespace B.S.Base.Read.API.Application.CommandHandLer
{
    public class GetDeptCommandHandLer : IRequestHandler<GetDeptCommand, APIResult<List<object>>>
    {

      private readonly  IBaseRepostiy<AccountModel> _accountModel;
        private readonly IBaseRepostiy<UserRoleModel> _userRoleModel;
        public GetDeptCommandHandLer(IBaseRepostiy<AccountModel> _accountModel, IBaseRepostiy<UserRoleModel> _userRoleModel)
        {
           this._accountModel = _accountModel;
            this._userRoleModel = _userRoleModel;
        }

        public async Task<APIResult<List<object>>> Handle(GetDeptCommand request, CancellationToken cancellationToken)
        {
            var result = _accountModel.GetAll().Where(x=>x.DeptId==request.DeptId).ToList();
            List<int> role=_userRoleModel.GetAll().Where(x=>x.RoleId==request.RoleId).Select(x=>x.AccountId).ToList();
            var entity = new List<object>()
            {
                result, role
            };
            return new APIResult<List<object>>
            {
                Code = ResultCode.Ok,
                Data = entity.ToList(),
                Message = ""
            };
        }
      
    }
}
